﻿namespace NorthernLights.Controls
{
    using System;
    using System.Windows;
    using NorthernLights.Controls.Tools;

    /// <summary>
    /// InputPopup class.
    /// </summary>
    public class InputPopup
    {
        #region Events
        /// <summary>
        /// The completed event.
        /// </summary>
        public event EventHandler<InputBoxEventArgs> Completed;
        #endregion

        #region Public properties
        /// <summary>
        /// Gets the Input value.
        /// </summary>
        public string Input { get; private set; }
        #endregion

        #region Public methods
        /// <summary>
        /// Shows the input popup.
        /// </summary>
        /// <param name="title">The title for the popup.</param>
        /// <param name="text">The text to display within the popup.</param>
        /// <param name="ok">The text for the Ok button.</param>
        /// <param name="cancel">The text for the Cancel button.</param>
        public void Show(string title, string text, string ok, string cancel)
        {
            this.Show(title, text, ok, cancel, null);
        }

        /// <summary>
        /// Shows the input popup.
        /// </summary>
        /// <param name="title">The title for the popup.</param>
        /// <param name="text">The text to display within the popup.</param>
        /// <param name="ok">The text for the Ok button.</param>
        /// <param name="cancel">The text for the Cancel button.</param>
        /// <param name="style">The style to use.</param>
        public void Show(string title, string text, string ok, string cancel, Style style)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                NotificationTool.ShowInput(
                    title,
                    text,
                    (input) =>
                    {
                        this.Input = input;
                        this.TriggerCompletedEvent(false);
                    },
                    () =>
                    {
                        this.TriggerCompletedEvent(true);
                    },
                    "ok",
                    "cancel", 
                    style);
            });
        }
        #endregion

        #region Private methods
        private void TriggerCompletedEvent(bool isCancelled)
        {
            if (this.Completed != null)
            {
                this.Completed(this, new InputBoxEventArgs(isCancelled));
            }
        }
        #endregion
    }
}